import Tools from '@/utils/Tools.js';
import { HTML_DOMAIN } from '@/constant/Config.js';
// #ifdef MP-WEIXIN
import ShareMpWechatMixin from '@/mixins/share-mp-wechat-mixins.js'
// #endif
// #ifdef APP-PLUS
import ShareAppMixin from '@/mixins/share-app-mixins.js'
// #endif
// #ifdef H5
import ShareH5Mixin from '@/mixins/share-h5-mixins.js'
// #endif
const ShareMixin = {
	// #ifdef MP-WEIXIN
	mixins: [ShareMpWechatMixin],
	// #endif
	// #ifdef APP-PLUS
	mixins: [ShareAppMixin],
	// #endif
	// #ifdef H5
	mixins: [ShareH5Mixin],
	// #endif
	data() {
		return {
			//以下是传入参数以flag
			shareParam: {
				object_type: 0,
				object_id: 0,
				object_path: '',
				object_query: ''
			},
			shareUsable: false,


			//分享配置,
			shareData: {
				share_brief: '',
				share_image: '',
				share_path: '',
				share_title: '',
				share_url: '',
				share_query: ''
			},

			actionList: [],
			// #ifdef APP-PLUS
			appSharePopup: null,
			// #endif
		}
	},
	methods: {
		initShareMessage(auto = false) {
			let { object_type, object_id, object_path, object_query } = this.shareParam;
			if (object_type > 0 && object_id >= 0) {
				const pages = getCurrentPages();
				object_path = object_path || pages[pages.length - 1].route;
				const object_url = HTML_DOMAIN + '/' + object_path + (object_query ? ('?' + object_query) : '');
				this.shareUsable = false;
				this.$u.api.getShareInfo(object_type, object_id, object_url).then(res => {
					if (res.code == 200) {
						this.shareData = { ...res.data.info, share_path: object_path, share_query: object_query }
						this.shareUsable = true;
						// #ifdef APP-PLUS
						this.initAppSharePopop(auto)
						// #endif
						// #ifdef H5
						this.initH5Share()
						// #endif
					}
				})
			}
			// this.shareData = {
			// 	shareUrl: this.joinShareUrl(shareData.shareUrl),
			// 	shareTitle: shareData.shareTitle || '穗穗婚恋',
			// 	shareContent: shareData.shareContent || '穗穗婚恋',
			// 	shareImg: shareData.shareImg || '',

			// }
		},
		// joinShareUrl(url) {
		// 	// #ifdef MP
		// 	let shareUrl = url || getCurrentPages()[0].route;
		// 	// #endif
		// 	// #ifndef MP
		// 	let shareUrl = 'https://wwww.suisui.com/' + (url || getCurrentPages()[0].route);
		// 	// #endif
		// 	if (shareUrl.indexOf('?') >= 0) {
		// 		shareUrl += '&shareId='
		// 	} else {
		// 		shareUrl += '?shareId='
		// 	}
		// 	return shareUrl;
		// },
		// openShare(callback) {
		// 	// #ifdef APP-PLUS
		// 	if (this.shareData) {
		// 		this.shareObj = appShare(this.shareData, res => {
		// 			callback && callback(res)
		// 		});
		// 	}
		// 	// #endif
		// },
		// closeShare() {
		// 	// #ifdef APP-PLUS
		// 	if (this.shareObj) {
		// 		this.shareObj.close();
		// 	}
		// 	// #endif
		// },
		// // #ifdef H5
		// initWechatJssdk() {

		// },
		// // #endif
		// // #ifdef APP-PLUS
		// initAppSharePopop() {
		// 	this.appSharePopup = new AppSharePopup({
		// 		shareInfo: this.shareData,
		// 		actionList: this.appActionList
		// 	});
		// },
		// onAppSharePopup() {
		// 	this.appSharePopup.show();
		// }

		// #endif

	}
}

export default ShareMixin;
